using System.Collections;
using System.Collections.Generic;
using JetBrains.Rider.Unity.Editor;
using UnityEngine;

public class TargetController : MonoBehaviour
{
    public int RingScore = 0;
    public ScoreController scoreController;
    // Start is called before the first frame update
    void Start()
    {
        scoreController = Singleton<ScoreController>.Instance;
    }

    // 检测碰撞
    void OnCollisionEnter(Collision other) {
        Transform arrow = other.gameObject.transform;
        if (arrow == null) return;
        if (arrow.tag == "arrow") {
            arrow.GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0); // 速度设置为0
            arrow.GetComponent<Rigidbody>().isKinematic = true;
            arrow.transform.rotation = transform.rotation; // 旋转角度相对
            arrow.transform.rotation = arrow.transform.rotation * Quaternion.Euler(-90, 0, 0);
            arrow.transform.parent = this.transform;
            scoreController.RecordScore(RingScore);
            arrow.tag = "onTarget";
            Debug.Log("target:" + transform.gameObject.tag);
            if (transform.tag == "target3") {
                arrow.transform.rotation = transform.rotation; // 旋转角度相对
                arrow.transform.rotation = arrow.transform.rotation * Quaternion.Euler(-90, 0, -90);
                // this.GetComponent<FallController>().isFalling = true;
                // Debug.Log("isFalling:" + this.GetComponent<FallController>().isFalling);
                // Destroy(this.gameObject);
            }
            else if (transform.tag == "target4") {
                arrow.transform.rotation = transform.rotation; // 旋转角度相对
                arrow.transform.rotation = arrow.transform.rotation * Quaternion.Euler(-90, 0, 0);
                // this.GetComponent<FallController>().isFalling = true;
                // Debug.Log("isFalling:" + this.GetComponent<FallController>().isFalling);
                // Destroy(this.gameObject);
            }
        }
    }
}
